package com.rm2pt.generator.springboot.LabManage.controller;
import com.rm2pt.generator.springboot.LabManage.service.*;
import com.rm2pt.generator.springboot.LabManage.Message.*;
import java.util.Date;
import com.rm2pt.generator.springboot.LabManage.utils.PreconditionException;
import com.rm2pt.generator.springboot.LabManage.utils.StandardOPs;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

@RestController
@RequestMapping("/CreateDailyService")
public class CreateDailyServiceController {
	
	//@Autowired HttpSession hs;
	
	@Autowired 
	private CreateDailyService createDailyService;
	
	@RequestMapping(value="/createDaily",method=RequestMethod.PUT)	
	public String createDaily(CreateDailyMessage createDailyMsg) {
		
		
		JSONObject object = new JSONObject();
		try {
			object.put("data", createDailyService.createDaily(createDailyMsg.id,createDailyMsg.type,createDailyMsg.groupId,createDailyMsg.studentId,createDailyMsg.content));
			object.put("msg", "success");
			object.put("code", "200");
		} catch (Exception e) {
			if (e instanceof PreconditionException) {
				object.put("msg", "PreConditionException");
			}else {
				object.put("msg", "PostConditionException");
				e.printStackTrace();
			}
			object.put("code", "400");
		}
		String s=JSON.toJSONString(object);
		return s;
	}
	@RequestMapping(value="/editDaily",method=RequestMethod.PUT)	
	public String editDaily(EditDailyMessage editDailyMsg) {
		
		
		JSONObject object = new JSONObject();
		try {
			object.put("data", createDailyService.editDaily(editDailyMsg.id,editDailyMsg.type,editDailyMsg.content));
			object.put("msg", "success");
			object.put("code", "200");
		} catch (Exception e) {
			if (e instanceof PreconditionException) {
				object.put("msg", "PreConditionException");
			}else {
				object.put("msg", "PostConditionException");
				e.printStackTrace();
			}
			object.put("code", "400");
		}
		String s=JSON.toJSONString(object);
		return s;
	}
	@RequestMapping(value="/finishDaily",method=RequestMethod.PUT)	
	public String finishDaily(FinishDailyMessage finishDailyMsg) {
		
		
		JSONObject object = new JSONObject();
		try {
			object.put("data", createDailyService.finishDaily(finishDailyMsg.id));
			object.put("msg", "success");
			object.put("code", "200");
		} catch (Exception e) {
			if (e instanceof PreconditionException) {
				object.put("msg", "PreConditionException");
			}else {
				object.put("msg", "PostConditionException");
				e.printStackTrace();
			}
			object.put("code", "400");
		}
		String s=JSON.toJSONString(object);
		return s;
	}
	
}
